<?php

/**
 * 
 * @author yuxun
 *
 */
class ChatService extends Service {
	
	public static function forbid($game_name,$plat_cname,$server_id,$plat_user_name,$role_id,$forbid_time,$army_id,$type){
		if($game_name == ''){
			$json_arr = array('state'=>1,'msg'=>'need to parameter game_name' );
			return $json_arr;
		}
		
		if($game_name != 'S10'){
			$json_arr = array('state'=>1,'msg'=>'Parameter value error game_name' );
			return $json_arr;
		}
		
		if($plat_cname == ''){
			$json_arr = array('state'=>1,'msg'=>'need to parameter plat_cname' );
			return $json_arr;
		}
		
		if($server_id == ''){
			$json_arr = array('state'=>1,'msg'=>'need to parameter server_id' );
			return $json_arr;
		}
		
		if($plat_user_name == ''){
			$json_arr = array('state'=>1,'msg'=>'need to parameter plat_user_name' );
			return $json_arr;
		}
		
		if($role_id == ''){
			$json_arr = array('state'=>1,'msg'=>'need to parameter role_id' );
			return $json_arr;
		}
		
		if($type == ''){
			$json_arr = array('state'=>1,'msg'=>'need to parameter type' );
			return $json_arr;
		}
		
		if($type != 'forbid' && $type != 'mute' && $type != 'army_kickout'){
			$json_arr = array('state'=>1,'msg'=>'parameter type error' );
			return $json_arr;
		}
		
		if($type == 'forbid' || $type == 'mute'){  //需要参数forbid_time
			if($forbid_time == ''){
				$json_arr = array('state'=>1,'msg'=>'need to parameter forbid_time' );
				return $json_arr;
			}
		}
		
		if($type == 'army_kickout'){
			if($army_id == ''){
				$json_arr = array('state'=>1,'msg'=>'need to parameter army_id' );
				return $json_arr;
			}
		}
		
		
		
		
		//查询专服主键id
		$modSpecialServer = new ModSpecialServer();
		$special_obj = $modSpecialServer->findByAttributes(array('game'=>'mango','special_id' => $plat_cname));
		if($special_obj){
			$special_info = $special_obj->getAttributes();
		}else{
			$json_arr = array('state'=>1,'msg'=>'plat_cname not found ');
			ApiBaseService::doLog($_POST, $json_arr);
			exit(json_encode($json_arr));
		}
		$special_id = $special_info['id'];
		
		//根据server_id plat_cname 查询服务器在库里的主键
		$modServer = new ModServer();
		$server_list = $modServer->getServerForSpeNum('mango',$special_id,$server_id);
		if(count($server_list) == 0){
			$json_arr = array('state'=>1,'msg'=>'server_id not found ');
			ApiBaseService::doLog($_POST, $json_arr);
			exit(json_encode($json_arr));
		}
		$server_id_id = $server_list[0]['id'];
		
		$params = array(
				'game_name'=>$game_name,
				'plat_cname'=>$plat_cname,
				'server_id'=>$server_id_id,
				'plat_user_name'=>$plat_user_name,
				'role_id'=>$role_id,
				'forbid_time'=>$forbid_time,
				'army_id'=>$army_id,
				'type'=>$type,
		);
		$result = self::send($params);
		
		//$result['state'] = true;
		if($result['state']){
			$json_arr = array('state'=>0,'msg'=>'success' );
			return $json_arr;
		}else{
			$json_arr = array('state'=>1,'msg'=>'fail' );
			return $json_arr;
		}

		
		
	}
	
	/**
	 * forbid(封号)/mute(禁言)/army_kickout(踢出帮派)
	 * @param unknown $data
	 * @return Ambigous <multitype:, multitype:boolean string , multitype:boolean multitype: unknown , multitype:boolean unknown mixed , multitype:boolean string Ambigous <multitype:string , number, mixed> >
	 */
	public static function send($data){
		$forbid_time = $data['forbid_time'] + time();
		if($data['type'] == 'forbid'){  //封号
			$params = array(
					'type'=> 'forbid',
					'plat_user_name' => $data['plat_user_name'],
					'forbid_time' => $forbid_time,
					
			);
		}
		
		if($data['type'] == 'mute'){ //禁言
			$params = array(
					'type'=> 'mute',
					'role_id' => $data['role_id'],
					'forbid_time' => $forbid_time,
			);			
		}
		
		if($data['type'] == 'army_kickout'){ // 踢出帮派
			$params = array(
					'type'=> 'army_kickout',
					'role_id'       => $data['role_id'],
					'army_id' => $data['army_id'],			
			);	
		}	
		
		$api = new ApiService($data['server_id']);
		return $api->quxuanCommonSetting($params);
	}

}